/**
 * 
 */
package ru.athena.runTool.Model;

import java.io.PrintStream;
import java.sql.Connection;
import java.sql.SQLException;

import ru.athena.runTool.LogWriter;
import ru.athena.runTool.blockTypes.CodeBlock;
import ru.athena.runTool.SQLEngine.*;

/**
 * @author corc_usr
 *
 */
public class OperationExecute implements Operation {

	private Connection conn_;

	public OperationExecute( Connection conn) {
		conn_ = conn;
	}

	/**
	 * execute current node from connection? passed to constructor
	 * @throws Exception 
	 */
	public void visit(LeafNode node) throws Exception {
		CodeBlock cb = (CodeBlock)node.getUserObject();
		if (cb.isExecutable()) {
			DbmsOutput	dbms = new DbmsOutput( conn_ );
			cb.execute(conn_);
			dbms.show( LogWriter.out() );
		}
	}

	/** 
	 * don't execute anything
	 * @throws Exception 
	 */
	public void visitEnter(CompositeNode node) throws Exception {
		
	}
	
	/** 
	 * don't execute anything
	 * @throws Exception 
	 */
	public void visitLeave(CompositeNode node) throws Exception {
		
	}

}
